package com.service.serviceImpl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.config.CacheKeyManager;
import com.mapper.VideoBannerMapper;
import com.model.VideoBanner;
import com.service.VideoBannerService;
import com.utils.BaseCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 轮播图的实现接口
 */
@Service
public class VideoBannerServiceImpl extends ServiceImpl<VideoBannerMapper, VideoBanner> implements VideoBannerService {



    @Autowired
    private BaseCache baseCache;

    /**
     * 轮播图视频列表
     * @return
     */
    @Override
    public List<VideoBanner> listVideoBanner() {
        try {
            Object cacheObj=baseCache.getTenMinuteCache().get(CacheKeyManager.INDEX_BANNER_KEY,()->{
                //缓存没有数据库找
                List<VideoBanner> bannerList=this.list();
                //存入内存，下次使用
                baseCache.getTenMinuteCache().put(CacheKeyManager.INDEX_BANNER_KEY,bannerList);
                return bannerList;
            });
            if(cacheObj instanceof List){
                return (List<VideoBanner>)cacheObj;
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
